/**
 * create by young (young2f@outlook.com) on 2020/9/12
 */


'use strict';
import React from 'react';
import {connect} from 'dva/index';
import {DatePicker, Form, Select} from 'antd';
import styles from '../../index.less';
import FormBase from '../../../components/Base/FormBase';
import moment from 'moment';
import 'moment/locale/zh-cn';
import DirTree from "../../../components/DirTree";
import PaymentDataFace from "../dataFace/PaymentDataFace";
import PaymentDataFaceMainMaterial from "../dataFace/material/PaymentDataFaceMainMaterial";
import PaymentDataFaceAuxMaterial from "../dataFace/material/PaymentDataFaceAuxMaterial";

moment.locale('zh-cn');
const {RangePicker} = DatePicker;
const _ = require('lodash');

const table = 'payment';
const title = '付款申请单';
const {Option} = Select;
@Form.create()
@connect(({
            user,
            global,
            dynamicLabel,
            procure,
            finance
          }) => ({...user, ...global, ...procure, ...finance, ...dynamicLabel}))
export default class PaymentApplyForTree extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }


  componentDidMount() {
    this.setState({});

  }

  onTreeNodeSelected = (node) => {
    if (!node) return;
    this.state.treeNode = node;
    this.componentDidMount();
  };
//todo
  onTreeDelete = (_id, result) => {

  };

  dataPage() {
    const {treeNode = {}} = this.state;
    const {mark} = treeNode;
    if (mark === '采购主材付款申请') {
      return <PaymentDataFaceMainMaterial
        // treeId={treeId}
        // treeName={name}
        treeNode={treeNode}
        callback={() => this.componentDidMount()}
      ></PaymentDataFaceMainMaterial>
    }
    if (mark === '采购辅材付款申请') {
      return <PaymentDataFaceAuxMaterial
        // treeId={treeId}
        // treeName={name}
        treeNode={treeNode}
        callback={() => this.componentDidMount()}
      ></PaymentDataFaceAuxMaterial>
    }
    return <PaymentDataFace
      // treeId={treeId}
      // treeName={name}
      treeNode={treeNode}
      callback={() => this.componentDidMount()}
    ></PaymentDataFace>;

  }

  render() {
    const {dispatch, _notify, expandedKeys} = this.props;

    return (
      <Form className={styles.content}>
        <DirTree
          width={"19%"}
          disableEdit={true}
          table={table}
          dispatch={dispatch}
          onTreeDelete={this.onTreeDelete}
          onTreeNodeSelected={this.onTreeNodeSelected}
          expandedKeys={expandedKeys}
          defaultExpandAll={true}
          title={title}
        > {this.dataPage()}</DirTree>
      </Form>
    );
  }
}
